import java.util.Set;

/**
 * Created by forcht on 2018/4/27.
 */
public class Solution {
    public boolean wordBreak(String s, Set<String> dict) {
        boolean[] dp=new boolean[s.length()+1];
        dp[0]=true;
        for(int i=1;i<=s.length();i++){
            for(int j=i-1;j>=0;j--){
                if(dp[j]&&dict.contains(s.substring(j,i))){
                    dp[i]=true;
                    break;
                }
            }
        }
        return dp[s.length()];
    }
}
